package cn.ylg.com.baisibudeijie.pro.base.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.ylg.com.baisibudeijie.mvp.presenter.impl.MvpBasePresenter;
import cn.ylg.com.baisibudeijie.mvp.view.impl.MvpFrament;

/**
 * Created by MyPC on 2016/10/18.
 * 项目的fragmnet;
 */
public  abstract  class BaseFragment<P extends MvpBasePresenter> extends MvpFrament<P> {
    //缓存视图;
    private View viewContant;
    private boolean isInit;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //创建视图
        /**
         * container :activity里的布局;
         */
        if (viewContant==null){
            viewContant = inflater.inflate(getContentView(),container,false);
            initContentView(viewContant);
        }
        //判断父是否为空是否添加了,如果存在我们就干掉他 从新添加;
        ViewGroup parent = (ViewGroup) viewContant.getParent();
        if (parent!=null){
            parent.removeView(viewContant);
        }
        return viewContant;
    }

    public abstract  int getContentView();
    public abstract void initContentView(View viewContant);

    @Override
    public P bindPresenter() {
        return null;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (!isInit){
            this.isInit = true;
            initData();
        }
    }
    public void initData(){

    }
}
